package com.allianz.webapps.controllers;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.allianz.webapps.https.interfaces.appMdp.AppMdp;
import com.allianz.webapps.https.interfaces.util.ObjectUtil;
import com.allianz.webapps.orderspojo.AppBase;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.ObjectMapper;

//http://localhost:8080/pad_marketing/main/editMdp.action  获取
//http://localhost:8080/pad_marketing/main/saveMdp.action  保存
@Controller
@RequestMapping(value="main")
public class AppMdpController {

	@Autowired
	private ObjectMapper objectMapper;
	@Autowired
	private AppMdp appmdp;
	@Autowired
	private ObjectUtil objectUtil;
	
	/**
	 * 编辑的请求
	 */
	@RequestMapping(value="editMdp")
	@ResponseBody
	public AppBase editMdp(@RequestParam(value="jsonParam") String jsonParam,HttpServletRequest request,HttpServletResponse response)
			throws Exception{
		AppBase appBase=(AppBase)objectMapper.readValue(jsonParam, AppBase.class);
		String body=appmdp.requestEditParam(appBase);
		JSONObject json=new JSONObject(body);
		String body1="";
		if (json.get("Body").equals(null)) {
			if(!("S").equals(json.getString("Status")))
				throw new Exception(json.getString("ErrMsg"));
			else
				return null;
		}else{
			body1=json.getString("Body");
			appBase=objectMapper.readValue(body1, AppBase.class);
		}
		return appBase;
	}
	
	/**
	 * 保存的请求 
	 */
	@RequestMapping(value="saveMdp")
	@ResponseBody
	public String saveMdp(@RequestParam(value="jsonParam") String jsonParam,HttpServletRequest request,HttpServletResponse response)
			throws Exception{
		AppBase obj=objectMapper.readValue(jsonParam, AppBase.class);
		String body=objectUtil.requestParam(obj, "app.saveMdp");
		return body;
		
	}
	
}
